package ljl.alg.wangzheng_camp.round1.array_and_list;

import commons.ListNode;

public class _offer_25_merge_two_sorted_list {
    
    // 不看题解了，没什么营养
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode h = new ListNode();
        ListNode d = h;
        while (l1 != null && l2 != null) {
            int v1 = l1.val, v2 = l2.val;
            if (v1 <= v2) {
                d.next = l1; l1 = l1.next;
            } else {
                d.next = l2; l2 = l2.next;
            }
            d = d.next;
        }
        d.next = l1 == null ? l2 : l1;
        return h.next;
    }
}
